#include "waveletTransform.h"
void WaveletTransform::multiplication(double **A, double **B, double ** C, int size)
{
    double W[size][size];

    for(int i=0; i<size; ++i)
    {
        for(int j=0; j<size; ++j)
        {
            double sum = 0;

            for(int k=0; k<size; ++k)
            {
                sum+=A[i][k]*B[k][j];
            }
            W[i][j]=sum;
        }
    }

    for(int i=0; i<size; ++i)
    {
        for(int j=0; j<size; ++j)
        {
            C[i][j]=W[i][j];
        }
    }
}

double** WaveletTransform::transform(double **Tab,int width, int height)
{
    double **transformTab;
    int i=512;

    int h=wavelet->H();

    transformTab=Tab;

    while(i>=h)
    {
        wavelet->reset();
        wavelet->init(i,false);

        multiplication(wavelet->W(),transformTab,transformTab,i);
        multiplication(transformTab,wavelet->WT(),transformTab,i);

        i=i>>1;
    }
    return transformTab;
}

double** WaveletTransform::reverseTransform(double **transformTab,int width, int height)
{
    double **reverseTab;

    reverseTab=transformTab;

    int h=wavelet->H();

    while(h<=512)
    {
        wavelet->reset();
        wavelet->init(h,true);

        multiplication(wavelet->WT(),reverseTab,reverseTab,h);
        multiplication(reverseTab,wavelet->W(),reverseTab,h);
        h=h<<1;
    }
    return reverseTab;
}
